﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SLIP.Core
{
    public class SLIPViewBase : UserControl
    {
        public SLIPViewBase(object vm)
        {
            if (vm == null)
            {
                throw new ArgumentNullException("ViewModel can't be null.");
            }
            DataContext = vm;
            if (DataContext is IDisposable)
            {
                Unloaded += new RoutedEventHandler(DisposeViewModel);
            }

        }

        public SLIPViewBase()
        {
            //Need the default constructor for designer, otherwise it will throw errors.
        }

        private void DisposeViewModel(object sender, RoutedEventArgs e)
        {
            //Debug.Assert(DataContext is IDisposable);

            ((IDisposable)DataContext).Dispose();
            DataContext = null;
        }
    }
}
